package edu.seu.mart.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SecurityKit {

    /**
     * 对字符串进行SHA-1加密
     */
    public static String encryption(String dest) {
        return encryption(dest, "SHA-1");
    }

    /**
     * 字符串加密
     */
    public static String encryption(String dest, String type) {
        try {
            MessageDigest md = MessageDigest.getInstance(type);
            md.update(dest.getBytes());
            byte[] digest = md.digest();
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}
